package com.ihr360.shared.basicstaffinfo.dao;

import com.ihr360.shared.basicstaffinfo.dto.SyncedBasicStaffInfo;
import com.ihr360.type.StaffStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.List;

/**
 * @author Stone.Shi
 * @description
 * @date 2018-03-07 10:31:32.
 */
public interface SyncedStaffInfoRepository extends JpaRepository<SyncedBasicStaffInfo, String>, JpaSpecificationExecutor<SyncedBasicStaffInfo> {

    List<SyncedBasicStaffInfo> findAllByCompanyIdAndStaffStatusAndStaffNameIn(
            String companyId, StaffStatus staffStatus, List<String> staffNameList);

    List<SyncedBasicStaffInfo> findAllByCompanyIdAndStaffNameIn(String companyId, List<String> staffNameList);

    int countByCompanyIdAndStaffStatusAndIdIn(String companyId, StaffStatus staffStatus, List<String> staffIds);

    SyncedBasicStaffInfo findByCompanyIdAndId(String companyId, String staffId);

    @Query(value = "select id,staffName from sc_synced_basic_staff_info where companyId=:companyId and id in :ids", nativeQuery = true)
    List<Object[]> findByCompanyIdAndIdsIn(@Param("companyId") String companyId, @Param("ids") List<String> ids);

    List<SyncedBasicStaffInfo> findByCompanyIdAndIdIn(@Param("companyId") String companyId, @Param("ids") Collection<String> ids);

    List<SyncedBasicStaffInfo> findByIdIn(@Param("ids") Collection<String> ids);

    List<SyncedBasicStaffInfo> findByCompanyIdAndStaffStatusNot(String companyId, StaffStatus staffStatus);

    @Query(" select companyId from SyncedBasicStaffInfo group by companyId having companyId not in :exitCompanyIds  ")
    List<String> findAllCompanyIdsExclude(@Param("exitCompanyIds") List<String> exitCompanyIds);

    @Query(" select  companyId from SyncedBasicStaffInfo group by companyId ")
    List<String> findAllCompanyIds();

    List<SyncedBasicStaffInfo> findByCompanyIdAndIdNotIn(String companyId, List<String> exitStaffIds);

    List<SyncedBasicStaffInfo> findByCompanyId(String companyId);
}
